package imoocvideodev.common.config;

import imoocvideodev.controller.interceptor.MiniInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @Author: Redi
 * @Date: 2021/2/4 16:44
 * @Description: MVC映射配置类
 */
@Configuration
//WebMvcConfigurerAdapter 已废弃。故使用 WebMvcConfigurer接口
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/META-INF/resources/")
                .addResourceLocations("file:D:/tmpCode/imooc-video-user-data/");
    }

    @Bean
    public MiniInterceptor miniInterceptor(){
        return new MiniInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(miniInterceptor())
                .addPathPatterns("/user/**")
                .addPathPatterns("/video/upload.do", "/video/uploadCover.do", "/video/userLike.do",
                        "/video/userUnLike.do", "/video/saveComment.do")
                .addPathPatterns("/bgm/**")
                .excludePathPatterns("/user/getPublisher.do");
        super.addInterceptors(registry);
    }
}
